(function (_super) {
    function Tips(text) {
        Tips.super(this);

        this.tips = null;
        this.BG = null;

        this.init(text);
    }
    Laya.class(Tips, "Game.Tips", _super);
    var _proto = Tips.prototype;
    _proto.destroy = function () {
        _super.prototype.destroy.call(this, true);

        this.tips = null;
        this.BG = null;        
    }

    _proto.init = function (text) {
        this.alpha = 0;
        this.size(820, 120);
        this.pos(GAME_CONFIG.WIDTH + this.width, 300);

        var BG = new Laya.Image("res/game/ui/tips_bg.png");
            BG.size(this.width, this.height);
        
        var tips = new Laya.Label(text);
            tips.align = "center";
            tips.font = "font_game";
            tips.size(this.width, 56);
            tips.centerY = 0;

        this.BG = BG;
        this.tips = tips;
        this.addChildren(BG, tips);

        Laya.Tween.to(this, {alpha : 1, x : GAME_CONFIG.WIDTH / 2 - this.width / 2}, 500, Laya.Ease.circOut, Laya.Handler.create(this, function () {
            Laya.Tween.to(this, {alpha : 0, x : - this.width}, 500, Laya.Ease.circOut, Laya.Handler.create(this, function () {
                this.destroy();
            }), 500);
        }));
    }
})(Laya.Sprite);

(function () {
    var io = ppt.io;

    var PropTipItem = (function (_super) {
        var Pool = [];
        function PropTipItem(userName, itemName) {
            PropTipItem.super(this);

            this.BG = null;
            this.tipMsg = null;

            this.init(userName, itemName);
        }
        Laya.class(PropTipItem, "", _super);
        var _proto = PropTipItem.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            this.BG = null;
            this.tipMsg = null;
        }
        _proto.init = function (userName, itemName) {
            this.size(270, 30);

            var BG = new Laya.Image("res/game/ui/tips_get_prop.png");
                BG.sizeGrid = "24,135,26,135";
                BG.right = 0;
                BG.centerY = 0;

            var tipMsg = new Laya.HTMLDivElement();
                tipMsg.style.align = "right";
                tipMsg.style.font = "Impact";
                tipMsg.style.fontSize = 20;
                tipMsg.size(500, 20);
                tipMsg.pos(this.width - tipMsg.width - 50, this.height / 2 - tipMsg.height / 2);

            this.tipMsg = tipMsg;
            this.BG = BG;
            this.addChildren(BG, tipMsg);
            
            this.setup(userName, itemName);
        }
        _proto.setup = function (userName, itemName) {
            this.x = this.width;
            
            this.tipMsg.innerHTML = "<span style='color:#ffffff;'>" + (utils.getStringLength(userName) > 10 ? utils.cutStr(userName, 10) : userName) + "&nbsp;&nbsp;&nbsp;获得" + "</span>" + "<span style='color:#fffc00;'>" + itemName + "</span>";
            this.BG.width = this.tipMsg.contextWidth + 120;

            Laya.Tween.to(this, {x : 0}, 300, Laya.Ease.elasticOut);

            return this;
        }
        _proto.recover = function () {
            this.BG.width = 0;
            this.removeSelf();

            Pool.push(this);
        }

        PropTipItem.create = function (userName, itemName) {
            if(Pool.length !== 0){
                return Pool.pop().setup(userName, itemName);
            }else{
                return new PropTipItem(userName, itemName);
            }
        }
        PropTipItem.clear = function () {
            for(var i in Pool){
                Pool[i].destroy();
                delete Pool[i];
            }
        }

        return PropTipItem;
    })(Laya.Image);

    (function (_super) {
        function PropTip() {
            PropTip.super(this);
            
            this.tipList = [];
            this.maxTipsNum = 5;
            this.updateInterval = 1250;

            this.init();
        }
        Laya.class(PropTip, "Game.PropTip", _super);
        var _proto = PropTip.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            io.unregister("role::prop", this.add);

            this.tipList = null;
            this.maxTipsNum = null;
            this.updateInterval = null;
        }

        _proto.init =function () {
            this.size(270, 200);
            this.pos(GAME_CONFIG.WIDTH - this.width, 100);

            io.register("role::prop", this, this.add);
        }
        _proto.update = function () {
            if(this._childs.length !== 0){
                this.tipList.shift().recover();

                for(var i in this.tipList){
                    this.tipList[i].y -= this.tipList[i].height;
                }

                Laya.timer.once(this.updateInterval, this, this.update);
            }
        }
        _proto.add = function (data) {
            if(this.tipList.length >= 5){
                this.tipList.shift().recover();
                for(var i in this.tipList){
                    this.tipList[i].y -= this.tipList[i].height;
                }
            }
            var prop = PropTipItem.create(data.userName, data.itemName);
                prop.y = (this.tipList.length - 1) * prop.height;

            this.tipList.push(prop);
            this.addChild(prop);

            Laya.timer.clear(this, this.update);
            Laya.timer.once(this.updateInterval, this, this.update);
        }
    })(Laya.Sprite);
})();